import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 打开浏览器
driver = webdriver.Chrome()
# 输入网址
driver.get('http://novel.hctestedu.com/user/login.html')
# 浏览器最大化
# driver.maximize_window()
# 输入账户
# 显示等待-presence_of_element_located(locator)
el_ec = (By.XPATH, '//*[@id="txtUName"]')
el = WebDriverWait(driver, 10).until(EC.presence_of_element_located(el_ec))
el.send_keys('17730676645')

# el = driver.find_element(By.XPATH, '//*[@id="txtUName"]')
# el.send_keys('17730676645')

# 显示等待-visibility_of_element_located(locator)
pwd_ec = (By.XPATH, '//*[@id="txtPassword"]')
pwd = WebDriverWait(driver, 10).until(EC.visibility_of_element_located(pwd_ec))
pwd.send_keys('413301yl')

# pwd = driver.find_element(By.XPATH, '//*[@id="txtPassword"]')
# pwd.send_keys('413301yl')

# 显示等待-element_to_be_clickable(locator)
bt_ec = (By.XPATH, '//*[@id="btnLogin"]')
bt = WebDriverWait(driver, 10).until(EC.element_to_be_clickable(bt_ec))
bt.click()

# 检查标题是不是一致的
el=WebDriverWait(driver,10).until(EC.title_is("读书屋_原创小说网站"))
print('测试标题',el)

# driver.find_element(By.XPATH, '//*[@id="btnLogin"]').click()
# 点击全部作品
driver.find_element(By.PARTIAL_LINK_TEXT, '全部作品').click()
# 点击30万字以下
driver.find_element(By.PARTIAL_LINK_TEXT, '30万字以下').click()
# 强制等待3秒
time.sleep(3)
# 关闭浏览器
driver.quit()
